﻿using AdminStyem.Application.Command.traceabilityCommand;
using AdminStyem.Domain.Entity;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.traceabilityCommandHandler
{
    public class TraceabilityFTCommandHandler : IRequestHandler<TraceabilityFTCommand, APIResult<object>>
    {

        IBaseRespository<Traceability> BaseTraceability;

        public TraceabilityFTCommandHandler(IBaseRespository<Traceability> baseTraceability)
        {
            BaseTraceability = baseTraceability;
        }

        public async Task<APIResult<object>> Handle(TraceabilityFTCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> ret = new APIResult<object>();
            var traceability = await BaseTraceability.GetByid(request.TraceabilityId);
            if (traceability != null)
            {
                ret.Code = ResultCode.查询成功;
                ret.Message = ResultCode.查询成功.ToString();
                ret.Data = traceability;
            }
            else
            {
                ret.Code = ResultCode.查询失败;
                ret.Message = ResultCode.查询失败.ToString();
            }
            return ret;
        }
    }
}
